bitkeeper revision 1.1550.1.3 (4294b356XJn1FHEVZ-2JlKpBDmqmpA)
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 25 May 2005 17:18:14 +0000 (17:18 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Wed, 25 May 2005 17:18:14 +0000 (17:18 +0000)
xc_linux_restore.c:
  Make read from network work.
  Make error messages more specific.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
tools/libxc/xc_linux_restore.c

index cc8e4b4d290a1654cb185ccb159904126a4d0829..57814ca0a86c2d5b42c22a5c414cf68d34f839ef 100644 (file)
 #define PPRINTF(_f, _a...)
 #endif
 
+ssize_t
+read_exact(int fd, void *buf, size_t count)
+{
+    int r = 0, s;
+    unsigned char *b = buf;
+
+    while (r < count) {
+       s = read(fd, &b[r], count - r);
+       if (s <= 0)
+           break;
+       r += s;
+    }
+
+    return r;
+}
+
 int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
 {
     dom0_op_t op;
@@ -90,7 +106,7 @@ int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
         return 1;
     }
 
-    if (read(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE) {
+    if (read_exact(io_fd, pfn_to_mfn_frame_list, PAGE_SIZE) != PAGE_SIZE) {
        ERR("read pfn_to_mfn_frame_list failed");
        goto out;
     }
@@ -168,9 +184,9 @@ int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
             prev_pc = this_pc;
         }
 
-        if ( read(io_fd, &j, sizeof(int)) != sizeof(int) )
+        if ( read_exact(io_fd, &j, sizeof(int)) != sizeof(int) )
         {
-            ERR("Error when reading from state file");
+            ERR("Error when reading batch size");
             goto out;
         }
 
@@ -192,9 +208,9 @@ int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
             goto out;
         }
  
-        if ( read(io_fd, region_pfn_type, j*sizeof(unsigned long)) !=
+        if ( read_exact(io_fd, region_pfn_type, j*sizeof(unsigned long)) !=
              j*sizeof(unsigned long) ) {
-            ERR("Error when reading from state file");
+            ERR("Error when reading region pfn types");
             goto out;
         }
 
@@ -245,9 +261,9 @@ int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
             else
                 ppage = (unsigned long*) (region_base + i*PAGE_SIZE);
 
-            if ( read(io_fd, ppage, PAGE_SIZE) != PAGE_SIZE )
+            if ( read_exact(io_fd, ppage, PAGE_SIZE) != PAGE_SIZE )
             {
-                ERR("Error when reading from state file");
+                ERR("Error when reading pagetable page");
                 goto out;
             }
 
@@ -389,9 +405,9 @@ int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
        unsigned int count, *pfntab;
        int rc;
 
-       if ( read(io_fd, &count, sizeof(count)) != sizeof(count) )
+       if ( read_exact(io_fd, &count, sizeof(count)) != sizeof(count) )
        {
-           ERR("Error when reading from state file");
+           ERR("Error when reading pfn count");
            goto out;
        }
 
@@ -402,10 +418,10 @@ int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
            goto out;
        }
 
-       if ( read(io_fd, pfntab, sizeof(unsigned int)*count) !=
+       if ( read_exact(io_fd, pfntab, sizeof(unsigned int)*count) !=
              sizeof(unsigned int)*count )
        {
-           ERR("Error when reading pfntab from state file");
+           ERR("Error when reading pfntab");
            goto out;
        }
 
@@ -432,10 +448,10 @@ int xc_linux_restore(int xc_handle, int io_fd, u32 dom, unsigned long nr_pfns)
        }       
     }
 
-    if ( read(io_fd, &ctxt,            sizeof(ctxt)) != sizeof(ctxt) ||
-         read(io_fd, shared_info_page, PAGE_SIZE) != PAGE_SIZE )
+    if ( read_exact(io_fd, &ctxt,            sizeof(ctxt)) != sizeof(ctxt) ||
+         read_exact(io_fd, shared_info_page, PAGE_SIZE) != PAGE_SIZE )
     {
-        ERR("Error when reading from state file");
+        ERR("Error when reading ctxt or shared info page");
         goto out;
     }